package com.ruoyi.web.controller.creditlife;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.creditlife.domain.BookBorrrowRecord;
import com.ruoyi.creditlife.service.IBookRenewRecordsService;
import com.ruoyi.creditlife.service.IReturnBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/creditlife/returnbook")
public class ReturnBookController {
@Autowired
    private IReturnBookService returnBookService;
@Autowired
    private IBookRenewRecordsService bookRenewRecordsService;

    @PreAuthorize("@ss.hasPermi('creditlife:borrowRecord')")
    @PutMapping
    public AjaxResult list(@RequestBody BookBorrrowRecord bookBorrrowRecord)
    {
        return AjaxResult.success(returnBookService.ReturnBook(bookBorrrowRecord));
    }

    @PreAuthorize("@ss.hasPermi('creditlife:borrowRecord')")
    @PutMapping("/renew")
    public AjaxResult reNewBook(@RequestBody BookBorrrowRecord bookBorrrowRecord,Long extendDays)
    {
        int flag = bookRenewRecordsService.ReNewBook(bookBorrrowRecord,extendDays);
        if(flag==-1){
            return AjaxResult.error("续借次数超过限制");
        }
        return AjaxResult.success();
    }
}
